package com.chexiehui.jc.mvp.mine;

import com.chexiehui.jc.Constants;
import com.chexiehui.jc.base.ApiCallback;
import com.chexiehui.jc.base.BaseModel;
import com.chexiehui.jc.base.BasePresenter;
import com.chexiehui.jc.entity.CarInfo;

import java.util.List;

/**
 * @Description 车辆列表
 * @Auth SongJun
 * @Date 2020/05/21 00:18
 **/
public class ChooseCarModelCarPresenter extends BasePresenter<ChooseCarModelCarCovenant.View, ChooseCarModelCarCovenant.Stores>
        implements ChooseCarModelCarCovenant.Presenter {

    public ChooseCarModelCarPresenter(ChooseCarModelCarCovenant.View view) {
        attachView(view);
    }

    @Override
    public void getList() {
        addSubscription(appStores.getList(mvpView.getSeriesId()),
                new ApiCallback<BaseModel<List<CarInfo>>>(mvpView) {
                    @Override
                    public void onSuccess(BaseModel<List<CarInfo>> model) {
                        if (model.getResultCode() == 0) {
                            if (model.getData() != null && model.getData().size() > 0) {
                                mvpView.onGetListSuccess(model);
                            } else {
                                onFailure(Constants.PAGE_DATA_EMPTY, "暂无车型信息");
                            }
                        } else {
                            onFailure(model.getResultCode(), model.getResultInfo());
                        }
                    }

                    @Override
                    public void onFailure(int code, String msg) {
                        mvpView.onGetListFailure(new BaseModel<>(code, msg));
                    }
                });
    }

}